﻿using KPI.Api.Apis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WPF_TY_UI;

namespace CssdAssistantClient.Views
{

    public partial class ViewPreviewTestQuestion : TYWindow
    {
        private readonly string qbId;

        public ViewPreviewTestQuestion(string qbId)
        {
            InitializeComponent();
            this.qbId = qbId;
            this.Loaded += ViewPreviewQuestion_Loaded;
        }

        private async void ViewPreviewQuestion_Loaded(object sender, RoutedEventArgs e)
        {
            var rData = await Run(() =>
            {
                return QuestionBankApi.GetQuestionAllInfo(this.qbId);
            });

            if (rData == null)
            {
                MessageBox.Show("数据异常,请检查日志!");
                return;
            }
            if (rData.code != 0)
            {
                MessageBox.Show("数据异常,code:" + rData.code + ":msg:" + rData.msg);
                return;
            }
            if (rData.data == null)
            {
                MessageBox.Show("数据为空!");
                return;
            }

            QuestionInfoModel questionInfoModel = new QuestionInfoModel();
            questionInfoModel.FromData(rData.data);
            this.DataContext = questionInfoModel;
        }

        private void BtnClick_Modify(object sender, RoutedEventArgs e)
        {
            ViewEditQuestion view = new ViewEditQuestion(this.qbId);
            view.ShowDialog();
        }
    }
}
